package cn.gailvlun.gll.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;

import cn.gailvlun.gll.R;
import cn.gailvlun.gll.presentation.login.adapter.GenderType;



public class GenderView extends AppCompatTextView {
    public GenderView(Context context) {
        this(context, null);
    }

    public GenderView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public GenderView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.GenderView);
        
        int genderFromXML = ta.getInt(R.styleable.GenderView_gender, -1);
        ta.recycle();

        if (genderFromXML == -1) {
            mGender = null;
        } else {
            mGender = GenderType.values()[genderFromXML];
        }
        setGenderType(mGender);

        initView();
    }

    private void initView() {

    }

    private GenderType mGender;

    public void setGenderType(@Nullable GenderType genderType) {
        mGender = genderType;
        if (genderType == null) {
            setBackground(null);
            setText(null);
            return;
        }
        setText(genderType.getCompliment());
        switch (genderType) {
            case male: {
                setBackgroundResource(R.drawable.rounded_robinsegg);
                break;
            }
            case female: {
                setBackgroundResource(R.drawable.rounded_carnation);
                break;
            }
            default: {

                break;
            }
        }
    }

    @Nullable
    public GenderType getGenderType() {
        return mGender;
    }

}
